<template>
  <el-container class="home-container">
    <!--头部-->
    <el-header>
      <div>
        <div class="avatar_box">
          <img src="../assets/logo.png" alt="欢迎进入管理系统" />
        </div>
      </div>
      <div>
        <span class="span_box">商户管理系统</span>
      </div>
      <el-button type="info" @click="loginOut">退出</el-button>
    </el-header>



    <!--主体-->
    <el-container>


      <!--侧边栏-->
      <el-aside :width="isCollapse ? '64px' : '200px'">
        <div class="toggle-button" @click="toggleCollpase">|||</div>
        <!--侧边栏菜单区域-->
        <el-menu
          class="el-menu-vertical-demo"
          background-color="#333744"
          text-color="#fff"
          active-text-color="#409eff"
          unique-opened
          :collapse="isCollapse"
          :collapse-transition="false"
          :router="true"
          :default-active="$route.path"
        >
          <!--一级菜单-->
          <el-submenu
            :index="index + ''"
            v-for="(item, index) in menuList"
            :key="index + ''"
          >
            <!--模板区-->
            <template slot="title">
              <!--图标-->
              <i :class="iconsObj[index]"></i>
              <!--文本-->
              <span>{{ item.title }}</span>
            </template>

            <!--二级菜单-->
            <el-menu-item
              :index="subItem.path"
              v-for="(subItem, subIndex) in item.children"
              :key="subIndex + ''"
            >
              <template slot="title">
                <!--图标-->
                <i class="el-icon-s-promotion"></i>
                <!--文本-->
                <span>{{ subItem.title }}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>

      <!--右侧主体-->
      <el-main>
        <!--路由占位符-->
        <router-view></router-view>
      </el-main>


    </el-container>


  </el-container>
</template>

<script>
export default {
  data() {
    return {
      //左侧菜单数据
      menuList: [
        {
          title: "话题管理",
          children: [{ title: "首页话题",path:"/topic" }],
        },
        {
            title:"商品管理",
            children:[{
                title:"商品首页",path:"/goods"
            }]
        },
        {
            title:"订单管理",
            children:[{
                title:"订单首页",path:"/order"
            }]
        },
        {
          title: "用户管理",
          children: [
            { title: "管理员设置",path:'/merchant' },
            { title: "会员管理",path:'' },
          ],
        },
        {
          title: "消息管理",
          children: [
            { title: "发送的消息",path:'' },
          { title: "收到的消息",path:'' },],
        },
      ],
      iconsObj: {
        0: "el-icon-s-shop",
        1: "el-icon-s-grid",
        2: "el-icon-s-finance",
        3: "el-icon-unlock",
      },
      //是否折叠（默认否）
      isCollapse: false,
    };
  },
  created() {
    // this.getMenuList()
  },
  methods: {
    loginOut() {
      window.sessionStorage.clear();
      this.$router.push("/login");
    },
    //获取所有菜单
    async getMenuList() {
      //console.log(this.consts.MENU_LIST_URL);
      const { data: res } = await this.$http.get(this.consts.MENU_LIST_URL);
      //console.log(res)
      if (res.code != 200) return this.$message.error(res.meta.msg);
      this.menuList = res.data.routes;
    },
    //点击按钮实现菜单的折叠与展开
    toggleCollpase() {
      this.isCollapse = !this.isCollapse;
    },
  },
};
</script>

<style lang="less" scoped>
.el-header {
  background-color: #373d41;
  display: flex;
  justify-content: space-between;
  padding-left: 0;
  align-items: center;
  color: #fff;
}

.avatar_box {
  border: 1px solid #eee;
  border-radius: 50%;
  height: 50px;
  width: 50px;
  padding: 4px;
  background-color: #ffffff;
  img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background-color: #eee;
  }
  position: absolute;
  transform: translate(0%, -50%);
}

.span_box {
  text-align: center;
  padding-left: 75px;
  font-size: 20px;
}

.el-aside {
  background-color: #333744;
  .el-menu {
    border-right: none;
  }
}

.el-main {
  background-color: #eaedf1;
}

.home-container {
  height: 100%;
}

.toggle-button {
  background-color: #4a5064;
  font-size: 10px;
  line-height: 24px;
  color: #fff;
  text-align: center;
  letter-spacing: 0.2em;
  cursor: pointer;
}
</style>
